home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Technology Seed / ADC Seed CD - July 1999.toast / Carbon SDK 1.0d10c3 / Sample Code / AppearanceSample / DialogWindow.cp < prev    next >
Encoding:
Text File  |  1999-05-01  |  5.3 KB  |  191 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        DialogWindow.cp
  3.  
  4.     Contains:    Dialog example using Appearance Manager primitives.
  5.  
  6.     Version:    Appearance 1.0 SDK
  7.  
  8.     Copyright:    © 1997 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     File Ownership:
  11.  
  12.         DRI:                Edward Voas
  13.  
  14.         Other Contact:        7 of 9, Borg Collective
  15.  
  16.         Technology:            OS Technologies Group
  17.  
  18.     Writers:
  19.  
  20.         (edv)    Ed Voas
  21.  
  22.     Change History (most recent first):
  23.  
  24.          <1>     9/11/97    edv        First checked in.
  25. */
  26.  
  27. #include "AppearanceSamplePrefix.h"
  28.  
  29. #include <Appearance.h>
  30. #include <MacWindows.h>
  31. #include "DialogWindow.h"
  32.  
  33. DialogWindow::DialogWindow() : BaseWindow( 129 )
  34. {
  35.     ::SetThemeWindowBackground( fWindow, kThemeActiveDialogBackgroundBrush, true );
  36. }
  37.  
  38. DialogWindow::~DialogWindow()
  39. {
  40. }
  41.  
  42. //ããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
  43. //    Ä Activate
  44. //ããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
  45. //    Activate our window by drawing all of our items in the active state.
  46. //
  47. void
  48. DialogWindow::Activate( EventRecord& )
  49. {
  50.     Rect            editTextRect = { 9, 9, 27, 101 };
  51.     Rect            portRect;
  52.  
  53.     ::SetPort( fPort );
  54.     GetPortBounds( fPort, &portRect );
  55.     ::DrawThemeModelessDialogFrame( &portRect, kThemeStateActive );
  56.     DrawFakeEditText( kThemeStateActive );
  57.     DrawFakeListBox( kThemeStateActive );
  58.     DrawGroups( kThemeStateActive );
  59.     DrawSeparators( kThemeStateActive );
  60.     ::DrawThemeFocusRect( &editTextRect, true );
  61. }
  62.  
  63. //ããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
  64. //    Ä Deactivate
  65. //ããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
  66. //    Deactivate our window by drawing all of our items in the inactive state.
  67. //
  68. void
  69. DialogWindow::Deactivate( EventRecord& )
  70. {
  71.     Rect        portRect;
  72.     Rect        editTextRect = { 9, 9, 27, 101 };
  73.     
  74.     ::SetPort( fPort );
  75.     ::GetPortBounds( fPort, &portRect );
  76.     ::DrawThemeModelessDialogFrame( &portRect, kThemeStateDisabled );
  77.     DrawFakeEditText( kThemeStateDisabled );
  78.     DrawFakeListBox( kThemeStateDisabled );
  79.     DrawGroups( kThemeStateDisabled );
  80.     DrawSeparators( kThemeStateDisabled );
  81.     ::DrawThemeFocusRect( &editTextRect, false );
  82. }
  83.  
  84. //ããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
  85. //    Ä Draw
  86. //ããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
  87. //    Draws our dialog frame, edit text, list box, group box frames, as well as visual
  88. //    separators.
  89. //
  90. void
  91. DialogWindow::Draw()
  92. {
  93.     ThemeDrawState        state;
  94.     Rect                portRect;
  95.  
  96.     ::SetPort( fPort );
  97.  
  98.     state = IsWindowHilited( fWindow ) ?
  99.                 (ThemeDrawState)kThemeStateActive :
  100.                 (ThemeDrawState)kThemeStateDisabled;
  101.  
  102.     ::GetPortBounds( fPort, &portRect );
  103.     ::DrawThemeModelessDialogFrame( &portRect, state );
  104.  
  105.     DrawFakeEditText( state );
  106.     DrawFakeListBox( state );
  107.     DrawGroups( state );
  108.     DrawSeparators( state );
  109. }
  110.  
  111. //ããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
  112. //    Ä DrawFakeEditText
  113. //ããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
  114. //    Draws a mock-up of an edit text box. Note that the edit text frame can actually
  115. //    be drawn outside of the rectangle given. You essentially pass it the content
  116. //    rectangle and it figures out where the frame and bevel should be.
  117. //
  118. void
  119. DialogWindow::DrawFakeEditText( ThemeDrawState drawState )
  120. {
  121.     Rect                editTextRect = { 10, 10, 26, 100 };
  122.     ThemeDrawingState      state;
  123.     
  124.     ::SetPort( fPort );
  125.     
  126.     ::GetThemeDrawingState( &state );
  127.     ::NormalizeThemeDrawingState();
  128.     
  129.     ::EraseRect( &editTextRect );
  130.     ::DrawThemeEditTextFrame( &editTextRect, drawState );
  131.     
  132.     ::InsetRect( &editTextRect, -1, -1 );
  133.     ::DrawThemeFocusRect( &editTextRect, IsWindowHilited( fWindow ) );
  134.  
  135.     ::SetThemeDrawingState( state, true );
  136. }
  137.  
  138. //ããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
  139. //    Ä DrawFakeListBox
  140. //ããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
  141. //    Draws a mock-up of an list box. Note that the list frame can actually
  142. //    be drawn outside of the rectangle given. You essentially pass it the content
  143. //    rectangle and it figures out where the frame and bevel should be.
  144. //
  145. void
  146. DialogWindow::DrawFakeListBox( ThemeDrawState drawState )
  147. {
  148.     Rect                editTextRect = { 36, 10, 100, 100 };
  149.     ThemeDrawingState      state;
  150.     
  151.     ::SetPort( fPort );
  152.     
  153.     ::GetThemeDrawingState( &state );
  154.     ::NormalizeThemeDrawingState();
  155.     
  156.     ::EraseRect( &editTextRect );
  157.     ::DrawThemeListBoxFrame( &editTextRect, drawState );
  158.     ::SetThemeDrawingState( state, true );
  159. }
  160.  
  161. //ããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
  162. //    Ä DrawGroups
  163. //ããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
  164. //    Draws a primary and secondary group box.
  165. //
  166. void
  167. DialogWindow::DrawGroups( ThemeDrawState drawState )
  168. {
  169.     Rect        primaryRect = { 10, 110, 110, 210 };
  170.     Rect        secondaryRect = { 20, 120, 100, 200 };
  171.     
  172.     ::DrawThemePrimaryGroup( &primaryRect, drawState );
  173.     ::DrawThemeSecondaryGroup( &secondaryRect, drawState );
  174. }
  175.  
  176. //ããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
  177. //    Ä DrawSeparators
  178. //ããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
  179. //    Simple visual separators
  180. //
  181. void
  182. DialogWindow::DrawSeparators( ThemeDrawState drawState )
  183. {
  184.     Rect        vertRect = { 120, 110, 125, 210 };
  185.     Rect        horizRect = { 10, 220, 110, 225 };
  186.     
  187.     ::DrawThemeSeparator( &vertRect, drawState );
  188.     ::DrawThemeSeparator( &horizRect, drawState );
  189. }
  190.  
  191.